<!doctype html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
        <style>
            a {
                font-size: 20px;
            }
        </style>
    </head>
    <body>
        <div>
            <a href="https://www.absss.com">a</a>
            <a href="http://www.abssx.com">b</a>
            <a href="http://www.abssx.com">c</a>
            <a href="http://www.abssxx.com">d</a>
            <a href="http://www.ssxxx.com">e</a>
        </div>

        <script type="text/javascript">
            // 获取页面上所有的a标签
            var links = document.getElementsByTagName("a");
            // 为每个a标签添加点击事件监听器
            for (var i = 0; i < links.length; i++) {
                links[i].addEventListener("click", function (event) {
                    event.preventDefault();
                    // 获取点击的a标签的href属性
                    var href = this.getAttribute("href");
                    // 判断href是否以https开头
                    if (href.startsWith("https")) {
                        console.log("HTTPS链接:", href);
                    } else {
                        console.log("非HTTPS链接:", href);
                        // 阻止默认的跳转行为，如果你需要的话
                    }
                });
            }
        </script>

        <script type="text/javascript">
            // 为body添加点击事件监听器
            document.body.addEventListener("click", function (event) {
                // 检查点击的是否是a标签
                var target = event.target; // currentTarget
                while (target && target.nodeName !== "A") {
                    target = target.parentNode;
                }

                if (target && target.nodeName === "A") {
                    // 获取a标签的href属性
                    var href = target.getAttribute("href");

                    // 判断href是否以https开头
                    if (href && href.startsWith("https")) {
                        console.log("HTTPS链接:", href);
                    } else {
                        console.log("非HTTPS链接:", href);
                        // 阻止默认的跳转行为，如果你需要的话
                        // event.preventDefault();
                    }
                }
            });
        </script>
    </body>
</html>
